package com.it.ssh.action;

import java.util.List;

import com.it.ssh.entity.Book;
import com.it.ssh.entity.Book;
import com.it.ssh.service.BookService;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

public class BookAction extends ActionSupport implements ModelDriven<Book> {
	Book book = new Book();
	
	
	private BookService bookService;

	
	public void setBookService(BookService bookService) {
		this.bookService = bookService;
	}
	private List<Book> list;
	
	public List<Book> getList() {
		return list;
	}
	public void setList(List<Book> list) {
		this.list = list;
	}
	@Override
	public Book getModel() {
		// TODO Auto-generated method stub
		return book;
	}
	
	public String delete() throws Exception {
		boolean flag = bookService.delete(book.getId());
		System.out.println("hello:"+book.getId());
		String path = INPUT;
		if(flag) {
			path = SUCCESS;
		}
		return path;
	}
	public String queryAll() throws Exception {
		list=bookService.queryAll();		
		return SUCCESS;
	}
	public String queryById(int id) {
		book = bookService.queryById(id);
		return SUCCESS;
	}
	public String add() {
		boolean flag = bookService.add(book);
		String path = INPUT;
		if(flag) {
			path = SUCCESS;
		}
		return path;
	}
	public String update() {
		boolean flag = bookService.update(book);
		String path = INPUT;
		if(flag) {
			path = SUCCESS;
		}
		return path;
	}
	
}
